const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
  return sequelize.define('t_message_logs', {
    id: {
      autoIncrement: true,
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: '消息id'
    },
    tenant_id: {
      type: DataTypes.BIGINT,
      allowNull: false,
      defaultValue: 0,
      primaryKey: true,
      comment: '租户id'
    },
    create_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '发送时间'
    },
    sender: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '发送人id'
    },
    receiver: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '接收人，JSON数组'
    },
    title: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '消息标题'
    },
    message: {
      type: DataTypes.STRING(500),
      allowNull: true,
      comment: '消息内容'
    },
    module: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '对应模块'
    },
    msg_type: {
      type: DataTypes.STRING(200),
      allowNull: true,
      defaultValue: 'user',
      comment: '消息类型 user-用户消息 system-系统'
    },
    read_time: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '读消息时间'
    },
    wx_return: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '微信消息返回结果'
    },
    dd_return: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '钉钉消息返回结果'
    }
  }, {
    sequelize,
    tableName: 't_message_logs',
    timestamps: false,
    freezeTableName: true,
    indexes: [
      {
        name: 'PRIMARY',
        unique: true,
        using: 'BTREE',
        fields: [
          { name: 'id' },
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_tenant_id',
        using: 'BTREE',
        fields: [
          { name: 'tenant_id' }
        ]
      },
      {
        name: 'idx_sender',
        using: 'BTREE',
        fields: [
          { name: 'sender' }
        ]
      }
    ]
  });
};
